﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IosDatamodel;
using System.Web.Mvc;
using System.Data.Entity;
using System.Data;
using IOSpro.Lib;
using IOSpro.Models;
namespace IOSpro.Lib
{

    public class VideosBL : IVideosBL
    {
        private IosDBEntities db;
        private ModelStateDictionary _errorLog;

        public VideosBL(ModelStateDictionary modelState)
        {
            _errorLog = modelState;
            db = new IosDBEntities();
        
        }



        public VideosBL()
        {
           
            db = new IosDBEntities();

        }
        public bool SaveVideoinfo(VideoInfo Model, string VideoSheets)
        {
            Videos videoinfo = new Videos
            {

                VideoIntroduction = Model.VideoIntroduction,
                VideoIssue = Model.VideoIssue,
                DateTime = DateTime.Now,
                VideoSheetId = Convert.ToInt32(VideoSheets)
            };
        db.Videos.Add(videoinfo);       
        db.SaveChanges();
        return true;
        }

        public bool SaveVideourl(int videoid, string videotilte) 
        {
      //      Videos old = db.Videos.Where(a => a.Id == id).SingleOrDefault();
            //Videos videonew = new Videos
            //     {
            //         Id = videoid,
            //         VideoUrl = videourl
            //     };

            db.Videos.Where(a => a.Id == videoid).FirstOrDefault().VideoTitle = videotilte;
          
                      db.SaveChanges();         
        return true;
        
        }

        public bool SaveVideoimage(int videoid, string videoimage) 
        {
            //Videos videonew = new Videos
            //{
            //    Id = videoid,
            //    VideoImage = videoimageurl

            //};
       //     db.Videos.Attach(videonew);
            db.Videos.Where(a => a.Id == videoid).FirstOrDefault().VideoImage =videoimage;
            db.SaveChanges();
            return true;
             
        }


        public IQueryable<Videos> GetAllVideosInfo() 
        {
            return db.Videos.OrderBy(a => a.Id);       
        }
    }
}